package com.netmi.myjectpack.viewmodel;

import androidx.lifecycle.LiveData;

import com.netmi.myjectpack.bean.UserInfo;

import java.math.BigDecimal;

/**
 * 类描述：扩展 LiveData
 * 创建人：tgw
 * 创建时间：2020/8/6
 * 修改备注：
 */
public class StockLiveData extends LiveData<UserInfo> {
    private StockLiveDataManager stockManager;

    private static StockLiveData stockLiveData;

    private SimplePriceListener listener = new SimplePriceListener() {
        @Override
        public void onPriceChanged(UserInfo price) {
            setValue(price);
        }
    };

    private StockLiveData(String symbol) {
        stockManager = new StockLiveDataManager(symbol);
    }

    public static StockLiveData getStockLiveData() {
        if (stockLiveData == null) {
            stockLiveData = new StockLiveData("");
        }
        return stockLiveData;
    }

    public void updataData() {
        stockManager.requestPriceUpdates(listener);
    }

    @Override
    protected void onActive() {
        updataData();
    }

    @Override
    protected void onInactive() {
        stockManager.removeUpdates(listener);
    }
}

